package persistence;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.logging.Logger;

/**
 * This class exports all the logged errors and warnings to a file.
 * @author HTTPDragon Team
 */
    @SuppressWarnings("LoggerStringConcat")
public class LoggerExport {
    private static final Logger logger = Logger.getLogger("HTTPDragon Log");
    /**
     * This method writes an error to the log file.
     * @param bestandsPad the log file's path.
     * @param bestandNaam the log file's name.
     * @param waarde the error string.
     */
    public void writeLine(File bestandsPad, File bestandNaam, String waarde){
    BufferedWriter output = null; 
      try {  
          // kijk of de map(pen) nog moet(en) gemaakt worden
          if(!(bestandsPad).exists()){          
              bestandsPad.mkdirs();//maak map(pen) aan
          }
          
          //schrijf de string 'waarde' weg in bestand 'bestandNaam', voeg nl char en sluit bestand
          output = new BufferedWriter( new FileWriter(bestandsPad.getCanonicalPath() +"/"+ bestandNaam,true)) ;            
          output.write(waarde);
          output.newLine();
          output.close();
      }
      catch ( SecurityException securityException )
      {
         logger.warning("You do not have write access to " + bestandNaam);
      }
      catch ( Exception ex )
      {
         logger.warning("Couldn't create the file " + bestandNaam);
      }

    }
}
